package com.peng.egmvc1.controller;

import com.peng.egmvc1.mapper.EmpMapper;
import com.peng.egmvc1.pojo.entity.Emp;
import com.peng.egmvc1.pojo.vo.EmpVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工控制类Controller
 * @Author peng
 * @Date 2024-04-22 19:55
 */
@RestController
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpMapper empMapper;

    @PostMapping("/insert")
    public String addEmp(Emp emp){
        int i = empMapper.addEmp(emp);
        if (i>0){
            return "员工添加成功";
        }
        return "员工添加失败";
    }

    @GetMapping("/select")
    public List<EmpVO> getAllEmp(){
        return empMapper.selectAllEmp();
    }

    @PostMapping("/update")
    public String updateEmp(Emp emp){
        int i = empMapper.updateEmp(emp);
        if (i>0){
            return "员工修改成功";
        }
        return "员工修改失败";
    }

    @GetMapping("/delete/{id}")
    public String deleteEmpById(@PathVariable Integer id){
        int i = empMapper.deleteEmp(id);
        if (i>0){
            return "员工删除成功";
        }
        return "员工删除失败";
    }
}
